package org.cmy.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.cmy.po.User;

import java.util.List;
import java.util.Set;

@Mapper
public interface UserMapper {
    @Select("SELECT id, username, password, enabled FROM user WHERE username = #{username}")
    User findByUsername(String username);

    @Select("SELECT r.name FROM role r " +
            "JOIN user_role ur ON r.id = ur.role_id " +
            "WHERE ur.user_id = #{userId}")
    Set<String> findRolesByUserId(Long userId);

    @Select("SELECT p.code FROM permission p " +
            "JOIN role_permission rp ON p.id = rp.permission_id " +
            "JOIN user_role ur ON rp.role_id = ur.role_id " +
            "WHERE ur.user_id = #{userId}")
    Set<String> findPermissionsByUserId(Long userId);
}